package com.lzs.chuku.controller;


import com.lzs.entity.Otherout;
import com.lzs.chuku.service.OtheroutService;
import com.lzs.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘中帅
 * @since 2020-11-23
 */
@RestController
@RequestMapping("/chuku/otherout")
public class OtheroutController {
    @Autowired
    private OtheroutService otheroutService;
    @PostMapping("addOtherOutorder")
    @ApiOperation("新增其他出库")
    public R addOtherOutorder(@RequestBody Otherout otherout){
        boolean b=true;
        Integer num=otherout.getQty();
        //TODO  缺少调用库存服务 根据商品id查询商品数量
        Integer num1=1000;
        if(num>num1){
            return R.error().message(otherout.getCommodityname()+"库存不足，请重新填写数量");
        }else{
           b= otheroutService.saveOrUpdate(otherout);
        }
        if (b){
            //TODO 缺少调用锁定商品库存的接口
            return R.ok().message("添加成功");
        }
        return R.error().message("添加失败");
    }

    @GetMapping("findotherordedrById")
    @ApiOperation("根据id查找其他订单")
    public R findotherordedrById(Integer otherorderid){
        Otherout otherout = otheroutService.getById(otherorderid);
        if (otherout!=null){
            return R.ok().message("成功").data("otherout",otherout);
        }
        return R.error().message("失败");
    }
    @GetMapping("check")
    @ApiOperation("审核其他出库")
    public R check(@RequestBody List<Long> otheroutids){
        return otheroutService.changeState(otheroutids,"1");
    }
}

